package com.jiyi.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

import com.swift.maintenance.activity.MainActivity;

public class ConnectionChangeReceiver extends BroadcastReceiver {
	
	private Context mContext;
	public ConnectionChangeReceiver(Context context){
		this.mContext = context;
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		ConnectivityManager connectivityManager=(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo  mobNetInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        NetworkInfo  wifiNetInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        
        
        if (!mobNetInfo.isConnected() && !wifiNetInfo.isConnected()) {
            //改变背景或者 处理网络的全局变量
        	Toast.makeText(context, "你现在处于离线状态", Toast.LENGTH_LONG).show();     	
        	Intent intent2 = new Intent(mContext,MainActivity.class);
        	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
        	mContext.startActivity(intent2 );     	
        }
	}

}
